import {queryUserList} from "../utils/Api";

export default {
    namespace: "user",

    state: {
        dataSource: [],
        tableLoading: false,
        pagination: {
            current: 1,
            pageSize: 10,
            total: 0,
        },
    },

    effects: {
        * queryUserEffects({payload}, {call, put}) {
            yield put({type: "user/requestUser", payload});
            const data = yield call(queryUserList, {
                name: payload.name,
                account: payload.account,
                email: payload.email,
                pageNum: payload.pageNum,
                pageSize: payload.pageSize,
            });
            yield put({type: "user/receiveUser", data});
        },
    },

    reducers: {
        requestUser(state) {
            return {
                ...state,
                tableLoading: true
            };
        },
        receiveUser(state, {payload}) {
            return {
                ...state,
                dataSource: payload.dataSource,
                tableLoading: false,
                pagination: payload.pagination
            };
        },
        changeLoading(state, {payload}) {
            return {
                ...state,
                tableLoading: payload
            };
        }
    },

}

